    #This file is part of evolveolution.

    #Foobar is free software: you can redistribute it and/or modify
    #it under the terms of the GNU General Public License as published by
    #the Free Software Foundation, either version 3 of the License, or
    #(at your option) any later version.

    #evolveolution is distributed in the hope that it will be useful,
    #but WITHOUT ANY WARRANTY; without even the implied warranty of
    #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #GNU General Public License for more details.

    #You should have received a copy of the GNU General Public License
    #along with evolveolution.  If not, see <http://www.gnu.org/licenses/>.
from random import *
def game(speed,energy,population):
	#seeds
	prey = [speed*10,energy*10,population * 100];
	tmppreys = preys = [];
	pq = randint(1,9)
	pe = randint(1,9)
	pp = randint(1,9)
	pred = [pq*10,pe*10,pp*100];
	tmppreds = preds = [];
	#genesis
	i = 0
	j = 0
	n = 2000
	for i in range (0,prey[2]):
		energy = randint(1,prey[1]);
		quality = randint(1,prey[0]);
		preys.append([quality,energy]);
	for i in range (0,pred[2]):
		energy = randint(1,pred[1]);
		quality = randint(1,pred[0]);
		preds.append([quality,energy]);
	#generations
	for s in range (0,n):
		#fighting
		for i in range(0,len(preds)):
			for j in range(0,len(preys)):
				if preds[i][0] > preys[j][0]:
					if preds[i][1] > 0:
						preys[j][1] = preys[j][1]-1;
				if preds[i][0] < preys[j][0]:
					if preys[j][1] > 0:
						preds[i][1] = preds[i][1] -1;
		tmppreds = [];
		for i in range(0,len(preds)):
			if preds[i][1] > 0:
				tmppreds.append(preds[i]);
		
		preds = [];
		preds = tmppreds;
		tmppreys=[];
	
		for i in range(0,len(preys)):
			#print preys[i][1];
			if preys[i][1] > 0:
				#print preys[i];
				tmppreys.append(preys[i]);
		preys = [];
		preys = tmppreys;
		#breed and evolve
		tmppreds = [];
		tmppreys = [];
		for i in range(1,len(preds)):
			maxenergy = (preds[i][1] + preds[i-1][1])//2;
			maxevolve = (preds[i][0] + preds[i-1][0])//2;	
			for j in range(0,2):
				quality = randint(maxevolve-2,maxevolve+2);
				energy = randint(maxenergy-2,maxenergy+2);
				tmppreds.append([quality,energy]);
		preds =[];
		preds = tmppreds;
		#print preds
		for i in range(1,len(preys)):
			maxenergy = (preys[i][1] + preys[i-1][1])//2;
			maxevolve = (preys[i][0] + preys[i-1][0])//2;	
			for j in range(0,2):
				quality = randint(maxevolve-2,maxevolve+2);
				energy = randint(maxenergy-2,maxenergy+2);
				tmppreys.append([quality,energy]);
		preys = [];
		preys = tmppreys;
		print "Generations:";
		print s;
		print "	prey alive:"
		print len(prey);
		print "	predators alive:"
		print len(preds);
		if len(preds) == 0:
			return 1;
			break;
		elif len(preys) == 0:
			return 0;
			break;	
